/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.ejbs;

import cassys.application.services.StudentManagementBeanRemote;
import cassys.data.DAOFactory;
import cassys.data.StudentDAO;
import cassys.domain.classManagement.Student;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;

/**
 *
 * @author User
 */
@Stateless(mappedName="StudentManagementBean")
public class StudentManagementBean implements StudentManagementBeanRemote {

    DAOFactory daoFactory = DAOFactory.instance(DAOFactory.HIBERNATE);
    StudentDAO studentDAO;

    @PostConstruct
    public void init() {
        System.out.println("Post Construct : Module Manager Bean");
        studentDAO = daoFactory.getStudentDAO();
    }

    @Override
    public List<Student> getAllStudents() {
        return studentDAO.findAll();
    }

    @Override
    public void createStudent(Student newStudent) {

        try {
            System.out.println("Persisting info :" + newStudent.toString());
            studentDAO.makePersistent(newStudent);
            System.out.println("Persistent done");

        } catch (Exception e) {
            System.out.println("err:" + e.getMessage());
            System.out.println("err:" + e.getStackTrace());
        }
    }

//    private Student mapNewStudent(Student student) {
//        Student newStudent = new Student(student.getName());
//        return newStudent;
//    }
    @Override
    public void updateStudent(Student student) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteStudent(Student student) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Student findByStudentId(long studentId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
